/**
 * date tools
 */
function isAddZero(num = 0) {
  return num > 10 ? `${num}` : `0${num}`;
}

/**
 * 获取目标时间戳
 */
function transToTimestamp(origin) {
  return new Date(origin).getTime();
}

/**
 * 获取时间戳下的精确时间
 */
function getExactTime(timestamp = new Date().getTime()) {
  const year = new Date(timestamp).getFullYear();
  const month = new Date(timestamp).getMonth() + 1;
  const day = new Date(timestamp).getDate();

  const hour = new Date(timestamp).getHours();
  const minute = new Date(timestamp).getMinutes();
  const second = new Date(timestamp).getSeconds();

  return `${year}-${isAddZero(month)}-${isAddZero(day)} ${isAddZero(
    hour
  )}:${isAddZero(minute)}:${isAddZero(second)}`;
}
/**
 * 获取年月日
 */
function getYMD(timestamp = new Date().getTime()) {
  const ymd = getExactTime(timestamp).split(" ")[0];

  return ymd;
}
/**
 * 获取时分秒
 */
function getHMS(timestamp = new Date().getTime()) {
  const hms = getExactTime(timestamp).split(" ")[1];

  return hms;
}
/**
 * 是否大于当前时间
 */
function isOverCurrent(target = new Date().getTime()) {
  return target > new Date().getTime();
}
/**
 * 获取天数间隔
 * @param {number} timestamp1
 * @param {number} timestamp2
 */
function getDayGap(timestamp1, timestamp2) {
  return new Date(timestamp1 - timestamp2).getDay();
}
/**
 * 日期范围是否超过天数
 */
function isOverGap(timestamp1, timestamp2, days = 90) {
  return getDayGap(timestamp1, timestamp2) > days;
}

export {
  transToTimestamp,
  getExactTime,
  getYMD,
  getHMS,
  isOverCurrent,
  getDayGap,
  isOverGap,
};
